<template>
  <div class="base-container">
    <t-form ref="form" :data="queryParams" label-width="80"
            @submit="()=>{this.pagination.current=1;this.queryParams.pageNum=1;this.getList()}"
            @reset="()=>{this.queryParams.pageNum=1;this.queryParams.pageNum=1;this.getList()}">
      <t-row style="border-bottom: 1px solid #E5E6EB;margin-bottom: 10px">
        <t-col :span="11" class="query-form-inline">
          <!--          <t-form-item label="业务名称" name="businessName">-->
          <!--            <t-input-->
          <!--              v-model="queryParams.businessName"-->
          <!--              clearable-->
          <!--              placeholder="请输入项目名称"-->
          <!--              style="width: 240px"-->
          <!--            />-->
          <!--          </t-form-item>-->
          <t-form-item label="业务类型" name="approveType">
            <t-select style="width: 240px" clearable v-model="queryParams.approveType"
                      :options="dict.type.bzh_approve_type">
            </t-select>
          </t-form-item>
        </t-col>
        <t-col :span="1" class="operation-container">
          <t-button theme="primary" type="submit"> 查询</t-button>
          <t-button theme="default" variant="outline" type="reset">重置</t-button>
        </t-col>
      </t-row>
    </t-form>
    <t-table
      rowKey="id"
      :data="data"
      :columns="columns"
      hover
      :pagination="pagination"
      :loading="dataLoading"
    >
      <template #[`localStandard.projectName`]="{ row }">
        <t-link @click="openDetail(row)" hover="color" theme="primary">{{ row.localStandard.projectName }}</t-link>
      </template>
      <template #[`localStandard.localStandardStatus`]="{ row }">
        <t-tag
          @click="dialog.header=row.localStandard.projectName;dialog.standardCategory=row.localStandard.standardCategory;dialog.objId=row.localStandard.id;dialog.open_approve_list=true"
          class="cursor-pointer"
          :theme="handleTheme(row.localStandard.localStandardStatus, dict.type.local_standard_status)" variant="light">
          {{ row.localStandard.localStandardStatus | filterByDict(dict.type.local_standard_status) }}
        </t-tag>
      </template>
      <template #[`localStandard.standardCategory`]="{ row }">
        {{ row.localStandard.standardCategory | filterByDict(dict.type.standard_category) }}
      </template>
      <template #approveType="{row}">
        {{ row.approveType|filterByDict(dict.type.bzh_approve_type) }}
      </template>
      <!--      <template #businessId="{row}">-->
      <!--        <t-link v-if="row.approveType === '1'" @click="dialog.objId=row.localStandard.id;dialog.header=row.localStandard.projectName;dialog.open_project_detail=true" hover="color" theme="primary">立项详情</t-link>-->
      <!--        <t-link v-else-if="row.approveType === '2'" @click="dialog.objId=row.project.id;dialog.header=row.project.projectName;dialog.open_outline_detail=true" hover="color" theme="primary">报审详情</t-link>-->
      <!--        <t-link v-else  hover="color" theme="primary">详情</t-link>-->
      <!--      </template>-->
      <template #op="{row}">
        <t-button @click="dialog.row=row;dialog.open=true" size="small" variant="text" class="t-button-link">
          <t-icon name="edit-1" slot="icon"/>
          审批
        </t-button>
      </template>
    </t-table>
    <standardDetailDialog :tabDefaultValue="dialog.tabDefaultValue" :header="dialog.header" :objId="dialog.objId"
                          :visible.sync="dialog.open_detail" v-if="dialog.open_detail">
    </standardDetailDialog>
    <approve-info :visible.sync="dialog.open"
                  @reload="getList()"
                  :row="dialog.row"
                  v-if="dialog.open"></approve-info>
    <approveList :header="dialog.header" :obj-id="dialog.objId" :standardCategory="dialog.standardCategory"
                 :visible.sync="dialog.open_approve_list" v-if="dialog.open_approve_list"></approveList>
  </div>
</template>

<script>
import approveInfo from "@/pages/bzh/approve/components/approve-info.vue";
import standardDetailDialog from "@/pages/bzh/standard/components/standard-detail-dialog.vue";
import approveList from "@/pages/bzh/approve/components/approve-list.vue";

export default {
  name: "approve-my",
  dicts: ["bzh_approve_type", "approve_status", "local_standard_status", "standard_category"],
  components: {
    approveInfo,
    standardDetailDialog,
    approveList,
  },
  data() {
    return {
      dialog: {
        open: false,
        objId: null,
        header: '',
        open_detail: false,
        open_approve_list: false,
        tabDefaultValue: '1'
      },
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        approveType: '',
        businessName: '',
      },
      data: [],
      columns: [
        {
          colKey: "localStandard.projectName",
          title: "标准名称",
          align: "center",
          // ellipsis: true,
          width: 220,
        },
        {
          colKey: "localStandard.standardCategory",
          title: "标准类别",
          align: "center",
          width: 100,
        },
        {
          colKey: "localStandard.localStandardStatus",
          title: "标准状态",
          align: "center",
        },
        // {
        //   colKey: "businessName",
        //   title: "业务名称",
        //   align: "center",
        //   ellipsis: true
        // },
        {
          colKey: "approveType",
          title: "审批业务类型",
          align: "center",
        },
        {
          colKey: "localStandard.declareDeptName",
          title: "填报单位",
          align: "center",
        },
        {
          colKey: "createTime",
          title: "创建时间",
          align: "center",
          width: 200
        },
        {
          colKey: "op",
          title: "操作",
          align: "center",
          width: 200
        },
      ],

      dataLoading: false,
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0,
        showPageSize: true,
        pageSizeOptions: [10, 20, 30, 50],
        showFirstAndLastPageBtn: false,
        onChange: (pageInfo) => {
          Object.assign(this.pagination, pageInfo)
          this.queryParams.pageNum = pageInfo.current || 1;
          this.queryParams.pageSize = pageInfo.pageSize;
          this.getList()
        },
      },
    }
  },
  async created() {
    this.getList()
  },
  methods: {
    getList() {
      this.dataLoading = true;
      this.$api.bzh.approve.myApproveList(this.queryParams).then(response => {
        this.pagination.total = response.total;
        this.data = response.rows;
        this.dataLoading = false;
      }).catch((e) => {
        this.dataLoading = false;
        this.$message.error(e.toString());
      });
    },
    openDetail(row) {
      this.dialog.header = row.localStandard.projectName;
      if (row.approveType === '1') {
        this.dialog.tabDefaultValue = '1'
      } else if (row.approveType === '2') {
        this.dialog.tabDefaultValue = '3';

      } else if (row.approveType === '3') {
        this.dialog.tabDefaultValue = '4';
      }
      this.dialog.objId = row.localStandard.id;
      this.dialog.open_detail = true
    }
  },
}
</script>

<style scoped>

</style>
